<?php
    include_once("Models/NguoiDung.php");
    
    if (isset($_POST['txtmaso']) && isset($_POST['txtmatkhau'])){
        $user = new NguoiDung();
        $user->setMaSo(trim($_POST['txtmaso']));
        $user->setMatKhau(md5(trim($_POST['txtmatkhau'])));
        if ($user->kiemTra()!=0){
            while ($rows = mysql_fetch_array($user->getResult())){
                $user->setMaQuyen($rows['maquyen']);
               
            }
            $nmaso = $user->getMaSo();
            $_SESSION["nmaso"] = $nmaso;
            //$maso = $_POST['txtmaso'];
            $nmaquyen = $user->getMaQuyen();
			$_SESSION["nmaquyen"] = $nmaquyen;
			if ($nmaquyen=='SV'){
				$sql = "select hoten from NguoiDung a,SinhVien b";
            	$sql .= " where a.maso = b.maso and a.maso = '".$nmaso."'";
			}
			else{
            	$sql = "select distinct concat(holot,' ',ten) as hoten from NguoiDung a,CanBo b";
            	$sql .= " where a.maso = b.maso and a.maso = '".$nmaso."'";
			}
            //echo $sql;
            $user->setQuery($sql);
            //echo $user->getQuery();
            $result = $user->fetchAll();
            while ($rows = mysql_fetch_array($result)){
                $_SESSION["nten"] = $rows['hoten'];               
            }
            
            //require('Views/Thongtincanhan.php');
           	//echo "<script language=javascript> window.location = 'index.php'; </ script>";
            echo "<script language=javascript> window.location = 'index.php?option=thongtincanhan'; </script>"; 
            //header("Location: index.php");            
            //echo "Xin chao ".$ten ."(".$user->getMaSo().")".".Ban da dang nhap thanh cong";
        }
        else{
            echo "<script language=javascript> alert('Tên đăng nhập hoặc mật khẩu không đúng.');window.location = 'index.php'; </script>";  
        }
            
    } 
    
    /*if (isset($_POST['txtmaso']) && isset($_POST['txtmatkhau'])){
        $user = new NguoiDung();
        $user->setMaSo($_POST['txtmaso']);
        $user->setMatKhau($_POST['txtmatkhau']);
        if ($user->kiemTra()!=0){
            while ($rows = mysql_fetch_array($user->getResult())){
                $user->setMaQuyen($rows['maquyen']);
               
            }
            
            $maso = $user->getMaSo();
            $maquyen = $user->getMaQuyen();
            $_SESSION["maso"] = $maso;
            
            $_SESSION["maquyen"] = $maquyen;
            
           
            
            //$maso = $user->getMaSo();
            //$maquyen = $user->getMaQuyen();
            //$sql = "select distinct concat(holot,' ',ten) as hoten from NguoiDung a,CanBo b";
            //$sql .= " where a.maso = b.maso and a.maso = '".$maso."'";
            //echo $sql;
            //$user->setQuery($sql);
            //echo $user->getQuery();
            //$result = $user->fetchAll();
           
            while ($rows = mysql_fetch_array($user->fetchAll())){
                $ten = $rows['hoten'];               
            }
            $_SESSION["ten"] = $ten;
            //require('Views/Thongtincanhan.php');
            echo "<script language=javascript> window.location = 'index.php?option=thongtincanhan'; </script>"; 
            //header("Location: index.php");            
            //echo "Xin chao ".$ten ."(".$user->getMaSo().")".".Ban da dang nhap thanh cong";
        }
        else{
            echo "<script language=javascript> alert('Tên đăng nhập hoặc mật khẩu không đúng.');window.location = 'index.php'; </script>";  
        }
            
    }*/
?>
